package apig.client.prof;

import java.util.*;

import javax.swing.*;

import org.apache.tools.ant.types.Commandline.Marker;

import apig.client.*;
import apig.client.prof.syllabus.*;
import apig.client.serviface.*;

import com.google.gwt.user.client.rpc.*;
import com.google.gwt.user.client.ui.*;

public class StudView extends VerticalPanel {

	private Student s;
	private Lab l;
	private Grid grid;
	private int revision;
	private AsyncCallback<List<Code>> codeCallback = new AsyncCallback<List<Code>>() {
		@Override
		public void onFailure(Throwable caught) {
			// TODO Auto-generated method stub
		}

		@Override
		public void onSuccess(List<Code> result) {
			reloadGrid(result);
		}
	};

	public StudView(Student s) {
		this.s = s;
	}

	public void setLab(Lab l) {
		this.l = l;
		startReladCodes();
	}

	private void startReladCodes() {
		// show reload process started
		clear();
		add(new Label("LOADING"));

		// send request for codes
		CodeQuery cq = new CodeQuery();
		if (l == null) {
			cq.labId = Lab.LAB_UNKNOWN_ID;
		} else {
			cq.labId = l.labId;
		}
		cq.revision = revision;
		cq.ownerId = s.id;
		Stubman.getStubman().getService().getCodes(cq, codeCallback);
	}

	private void reloadGrid(List<Code> result) {
		final int ROWS = 4;
		grid = new Grid(ROWS, 1);
		grid.setWidth("100%");
		grid.setHeight("100%");
		setCellWidth(grid, "100%");
		setCellHeight(grid, "100%");
		add(grid);
		// get all the codes of the selected student and lab
		grid.add(new Label("mda1"));
		grid.add(new Label("mda2"));
		grid.add(new Label("mda3"));
		grid.add(new Label("mda4"));

		// show reload process ended
	}
}
